using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Entities;
using DAL;
using BUS;
using Utility;
public partial class Admin_DanhsachDonhang : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Request.Url.ToString().Contains("dangnhap.aspx") == false
&& Session["UserName"] == null)
            Response.Redirect("~/Admin/dangnhap.aspx");
        if (!IsPostBack)
        {
            LoadData();
        }
    }
    private void LoadData()
    {
        int total = 0;
        Criteria cri = new Criteria();
        tbDonhangCollection dhCollection = tbDonhangBUS.Get(cri.Criter, hyperlinkPager.CurrentIndex, hyperlinkPager.PageSize,
        tbDonhangColumn.Madh.ToString(), OrderDirection.ASC.ToString(), out total);
        Repeater1.DataSource = dhCollection;
        Repeater1.DataBind();

        hyperlinkPager.ItemCount = total;
    }
    protected void hyperlinkPager_Command(object sender, CommandEventArgs e)
    {
        hyperlinkPager.CurrentIndex = int.Parse(e.CommandArgument.ToString());
        LoadData();
    }
    protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        if (e.Item.ItemType == ListItemType.Item
           || e.Item.ItemType == ListItemType.AlternatingItem)
        {
            tbDonhang dh = (tbDonhang)e.Item.DataItem;

            HyperLink hp_hd = (HyperLink)e.Item.FindControl("hp_hd");

            tbKhachhang kh = tbKhachhangBUS.GetByID(dh.Makh);
            if (kh != null)
            {
                Label lit_kh = (Label)e.Item.FindControl("lit_kh");
                lit_kh.Text=kh.Tenkh;
            }

            tbTrangthaidonhang tt= tbTrangthaidonhangBUS.GetByID(dh.Matinhtrangdh);
            if (tt != null)
            {
                Literal lit_tinhrang = (Literal)e.Item.FindControl("lit_tinhtrang");
                lit_tinhrang.Text = tt.Trangthai;
            }

            hp_hd.Text =dh.Madh.ToString();
            hp_hd.NavigateUrl = "Chitietdonhang.aspx?id=" + dh.Madh.ToString();
        }
    }
}
